package cn.test.controller;

import org.springframework.stereotype.Service;
import org.springframework.web.context.request.async.DeferredResult;

/**
 * @auther hanchao
 * @date 2016/11/11 18:55
 */
@Service
public class PushService {
    private DeferredResult<String> deferredResult;
    private String t;
    public DeferredResult<String> getAsyncUpdate(){
        deferredResult = new DeferredResult<String>();
        System.out.println (deferredResult+">>>>");
        t="testtest";
        return deferredResult;
    }
    //@Scheduled(fixedDelay = 1000)
    public void refresh(){
        //直到setResult,客户端阻塞才会中断
        System.out.println("-----------");
        if(deferredResult != null){
            deferredResult.setResult("test::"+System.currentTimeMillis());
        }
        System.out.println(deferredResult);
        System.out.println(t);
    }

}
